using System;
using System.Drawing;
using System.Windows.Forms;
using HuaRongDaoGame.Services;

namespace HuaRongDaoGame.Forms
{
    /// <summary>
    /// 设置窗体
    /// </summary>
    public partial class SettingsForm : Form
    {
        public GameDataService.GameSettings Settings { get; private set; }

        public SettingsForm(GameDataService.GameSettings settings)
        {
            this.Settings = settings;
            InitializeForm();
        }

        /// <summary>
        /// 初始化窗体
        /// </summary>
        private void InitializeForm()
        {
            this.Text = "游戏设置";
            this.StartPosition = FormStartPosition.CenterParent;
            this.FormBorderStyle = FormBorderStyle.FixedDialog;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Size = new Size(400, 500);
            this.BackColor = Color.LightGray;

            CreateControls();
        }

        /// <summary>
        /// 创建控件
        /// </summary>
        private void CreateControls()
        {
            // 标题标签
            var titleLabel = new Label
            {
                Text = "游戏设置",
                Font = new Font("微软雅黑", 16, FontStyle.Bold),
                ForeColor = Color.DarkBlue,
                TextAlign = ContentAlignment.MiddleCenter,
                Size = new Size(300, 30),
                Location = new Point(50, 20)
            };

            // 音效设置
            var soundCheckBox = new CheckBox
            {
                Text = "启用音效",
                Font = new Font("微软雅黑", 10),
                Location = new Point(50, 70),
                Size = new Size(200, 25),
                Checked = Settings.EnableSound
            };

            // 背景音乐设置
            var musicCheckBox = new CheckBox
            {
                Text = "启用背景音乐",
                Font = new Font("微软雅黑", 10),
                Location = new Point(50, 100),
                Size = new Size(200, 25),
                Checked = Settings.EnableMusic
            };

            // 动画效果设置
            var animationCheckBox = new CheckBox
            {
                Text = "启用动画效果",
                Font = new Font("微软雅黑", 10),
                Location = new Point(50, 130),
                Size = new Size(200, 25),
                Checked = Settings.EnableAnimation
            };

            // 难度设置
            var difficultyLabel = new Label
            {
                Text = "默认难度:",
                Font = new Font("微软雅黑", 10),
                Location = new Point(50, 170),
                Size = new Size(100, 25)
            };

            var difficultyComboBox = new ComboBox
            {
                Font = new Font("微软雅黑", 10),
                Location = new Point(150, 170),
                Size = new Size(150, 25),
                DropDownStyle = ComboBoxStyle.DropDownList
            };
            difficultyComboBox.Items.AddRange(new object[] { "简单", "中等", "困难" });
            difficultyComboBox.SelectedIndex = Settings.Difficulty - 1;

            // 主题设置
            var themeLabel = new Label
            {
                Text = "界面主题:",
                Font = new Font("微软雅黑", 10),
                Location = new Point(50, 210),
                Size = new Size(100, 25)
            };

            var themeComboBox = new ComboBox
            {
                Font = new Font("微软雅黑", 10),
                Location = new Point(150, 210),
                Size = new Size(150, 25),
                DropDownStyle = ComboBoxStyle.DropDownList
            };
            themeComboBox.Items.AddRange(new object[] { "默认", "经典", "现代" });
            themeComboBox.SelectedIndex = 0;

            // 语言设置
            var languageLabel = new Label
            {
                Text = "语言:",
                Font = new Font("微软雅黑", 10),
                Location = new Point(50, 250),
                Size = new Size(100, 25)
            };

            var languageComboBox = new ComboBox
            {
                Font = new Font("微软雅黑", 10),
                Location = new Point(150, 250),
                Size = new Size(150, 25),
                DropDownStyle = ComboBoxStyle.DropDownList
            };
            languageComboBox.Items.AddRange(new object[] { "简体中文", "English" });
            languageComboBox.SelectedIndex = 0;

            // 最大提示次数
            var maxHintsLabel = new Label
            {
                Text = "最大提示次数:",
                Font = new Font("微软雅黑", 10),
                Location = new Point(50, 290),
                Size = new Size(100, 25)
            };

            var maxHintsNumericUpDown = new NumericUpDown
            {
                Font = new Font("微软雅黑", 10),
                Location = new Point(150, 290),
                Size = new Size(80, 25),
                Minimum = 1,
                Maximum = 10,
                Value = Settings.MaxHints
            };

            // 自动保存设置
            var autoSaveCheckBox = new CheckBox
            {
                Text = "启用自动保存",
                Font = new Font("微软雅黑", 10),
                Location = new Point(50, 330),
                Size = new Size(200, 25),
                Checked = Settings.AutoSave
            };

            // 自动保存间隔
            var autoSaveIntervalLabel = new Label
            {
                Text = "自动保存间隔(分钟):",
                Font = new Font("微软雅黑", 10),
                Location = new Point(50, 360),
                Size = new Size(150, 25)
            };

            var autoSaveIntervalNumericUpDown = new NumericUpDown
            {
                Font = new Font("微软雅黑", 10),
                Location = new Point(200, 360),
                Size = new Size(80, 25),
                Minimum = 1,
                Maximum = 60,
                Value = Settings.AutoSaveInterval
            };

            // 确定按钮
            var okButton = new Button
            {
                Text = "确定",
                Font = new Font("微软雅黑", 10),
                Size = new Size(80, 30),
                Location = new Point(150, 400),
                BackColor = Color.LightBlue,
                FlatStyle = FlatStyle.Flat,
                DialogResult = DialogResult.OK
            };
            okButton.Click += (sender, e) =>
            {
                // 保存设置
                Settings.EnableSound = soundCheckBox.Checked;
                Settings.EnableMusic = musicCheckBox.Checked;
                Settings.EnableAnimation = animationCheckBox.Checked;
                Settings.Difficulty = difficultyComboBox.SelectedIndex + 1;
                Settings.Theme = themeComboBox.Text;
                Settings.Language = languageComboBox.SelectedIndex == 0 ? "zh-CN" : "en-US";
                Settings.MaxHints = (int)maxHintsNumericUpDown.Value;
                Settings.AutoSave = autoSaveCheckBox.Checked;
                Settings.AutoSaveInterval = (int)autoSaveIntervalNumericUpDown.Value;
            };

            // 取消按钮
            var cancelButton = new Button
            {
                Text = "取消",
                Font = new Font("微软雅黑", 10),
                Size = new Size(80, 30),
                Location = new Point(250, 400),
                BackColor = Color.LightCoral,
                FlatStyle = FlatStyle.Flat,
                DialogResult = DialogResult.Cancel
            };

            // 重置按钮
            var resetButton = new Button
            {
                Text = "重置默认",
                Font = new Font("微软雅黑", 10),
                Size = new Size(100, 30),
                Location = new Point(50, 400),
                BackColor = Color.LightYellow,
                FlatStyle = FlatStyle.Flat
            };
            resetButton.Click += (sender, e) =>
            {
                if (MessageBox.Show("确定要重置为默认设置吗？", "确认", 
                    MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    soundCheckBox.Checked = true;
                    musicCheckBox.Checked = true;
                    animationCheckBox.Checked = true;
                    difficultyComboBox.SelectedIndex = 0;
                    themeComboBox.SelectedIndex = 0;
                    languageComboBox.SelectedIndex = 0;
                    maxHintsNumericUpDown.Value = 3;
                    autoSaveCheckBox.Checked = true;
                    autoSaveIntervalNumericUpDown.Value = 5;
                }
            };

            // 添加控件
            this.Controls.AddRange(new Control[]
            {
                titleLabel,
                soundCheckBox,
                musicCheckBox,
                animationCheckBox,
                difficultyLabel,
                difficultyComboBox,
                themeLabel,
                themeComboBox,
                languageLabel,
                languageComboBox,
                maxHintsLabel,
                maxHintsNumericUpDown,
                autoSaveCheckBox,
                autoSaveIntervalLabel,
                autoSaveIntervalNumericUpDown,
                resetButton,
                okButton,
                cancelButton
            });

            // 设置默认按钮
            this.AcceptButton = okButton;
            this.CancelButton = cancelButton;
        }
    }
} 